<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
require_once( JPATH_COMPONENT.DS.'helpers'.DS.'farm.php' );

class FarmViewOperation extends JView
{
	function display()
	{
		$tableArr = array(			
			'erlist'	=> 'environmentRecord',
			'hrlist'	=> 'harvestRecord',
			'pplist'	=> 'plantPlan',
			'prlist'	=> 'plantRecord',
		);
		$layout = JRequest::getVar('layout');
		
		switch($layout){
			case 'hrlist':
				$t = JTable::getInstance($tableArr[$layout], 'Table');
				$tmp    = $t->hrlist();
				$this->assignRef('page',		$tmp[0]);
				$this->assignRef('data',		$tmp[1]);
				break;
			case 'pplist':
				$t = JTable::getInstance($tableArr[$layout], 'Table');
				$tmp    = $t->pplist();
				$this->assignRef('page',		$tmp[0]);
				$this->assignRef('data',		$tmp[1]);
				break;
			case 'erlist':
				$t = JTable::getInstance('obser', 'Table');
				$tmp    = $t->dataForOptions();
				$obserArr = array();
				foreach ($tmp as $k => $v) $obserArr[$v['id']] = $v['no'];
				$this->assignRef('obserArr',	$obserArr);
				
				$t = JTable::getInstance($tableArr[$layout], 'Table');
				$tmp    = $t->alist();
				$this->assignRef('page',		$tmp[0]);
				$this->assignRef('data',		$tmp[1]);
				
				break;//这个注释很重要			
			case 'prlist':
				$t = JTable::getInstance($tableArr[$layout], 'Table');
				$tmp    = $t->prlist();
				$this->assignRef('page',		$tmp[0]);
				$this->assignRef('data',		$tmp[1]);
				break;
			default:
				break;
		}
		parent::display();
	}
}
